package com.test2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main3 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        //while (in.hasNextInt()) {//注意while处理多个case
            int n = in.nextInt();
            int per = in.nextInt();
            String[] arr = new String[n]; 
            in.nextLine();
            for(int i=0;i<n;i++){
            	 arr[i] = in.nextLine();
            }
            String[] friend = arr[per].split(" ");
            Map<String,Integer> map = new HashMap<String,Integer>();
            for(int i=0;i<friend.length;i++){
            	String d = arr[Integer.parseInt(friend[i])];
            	String[] d2 = d.split(" ");
            	if(d2.length == 0){
            		return;
            	}
            	for(int j=0;j<d2.length;j++){
            		if(d2[j].equals(per+""))
            			continue;
            		if(map.containsKey(d2[j])){
            			map.put(d2[j], map.get(d2[j])+1);
            		}else{
            			map.put(d2[j], 1);
            		}
            	}
            }
            List<Map.Entry<String,Integer>> list = new ArrayList(map.entrySet());
            
            Collections.sort(list,(o1,o2)->(o1.getValue() - o2.getValue()));
            for(int i=0;i>list.size();i++){
            	 System.out.println(list.get(i).getKey());
            }
       // }
	}
	
}
